<template>
  <div class="app-container calendar-list-container">
   <div class="filter-container">
       <el-select @change='handleFilter' style="width: 160px" class="filter-item" v-model="search.status" placeholder="请选择状态">
          <el-option label="全部状态" value=''></el-option>
          <el-option v-for="option in stateOptions" :key="option.id"  :label="option.name"  :value="option.id"></el-option>
      </el-select>
       <el-select @change='handleFilter' style="width: 220px" class="filter-item" v-model="search.outlet" placeholder="请选择营业点" filterable>
          <el-option label="全部" value=''></el-option>
          <el-option v-for="option in outletOptions" :key="option.id"  :label="option.hotel_name"  :value="option.id"></el-option>
      </el-select>
      <el-button class="filter-item" type="primary" plain v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>
    <!-- // 这是列表 -->
    <el-table :data="listData" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row style="width: 100%">
      <el-table-column type="index"  align="center" label="序号" width="80"></el-table-column>
      <el-table-column align="center" label="用户名">
        <template slot-scope="scope">
          <span>{{scope.row.username}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="提现金额">
        <template slot-scope="scope">
          <span>{{scope.row.amount}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="收款码">
        <template slot-scope="scope">
         <span><img :src="scope.row.qr_code" style="width:50px;height:70px" onerror='this.src="http://wx.qlogo.cn/mmopen/C2rEUskXQiblFYMUl9O0G05Q6pKibg7V1WpHX6CIQaic824apriabJw4r6EWxziaSt5BATrlbx1GVzwW2qjUCqtYpDvIJLjKgP1ug/0"' /></span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="状态">
        <template slot-scope="scope">
           <el-tag type="draft">{{scope.row.status_name}}</el-tag>
        </template>
       </el-table-column>
      <el-table-column align="center" label="申请时间">
        <template slot-scope="scope" > 
           <span>{{scope.row.created_at}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="上次结算时间">
        <template slot-scope="scope">
          <span>{{scope.row.close_time}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="备注">
        <template slot-scope="scope">
          <span>{{scope.row.remark}}</span>
        </template>
      </el-table-column>
      <!-- //这里是操作   -->
      <el-table-column align="center" label="操作" class-name="small-padding fixed-width" fixed="right" width="180">
        <template slot-scope="scope">
          <el-button size="mini" v-if="scope.row.status==0 && scope.row.action_user==0" type="primary" @click="handlEdit(scope.row)">去结算</el-button>
          <el-button size="mini" v-else-if="scope.row.status==0 && scope.row.action_user!=0" type="primary">处理中..</el-button>
          <el-button size="mini" v-else plain type="info">已结算</el-button>
          <el-button size="mini" type="info" @click="handlLook(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--去结算窗口  -->
    <withraw-pay :visible.sync="editVisible" v-if="editVisible" :propsData="propsData" @refresh='isrefresh'></withraw-pay>  
    <!--去结算窗口  END -->

    <!--查看详情窗口  -->
    <look-draw-log  :visible.sync="lookVisible" @refresh='isrefresh' ref="lookLog"></look-draw-log>  
    <!--查看详情窗口  END -->

    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
    </div>
    
    <!--可自定义按钮的样式、show/hide临界点、返回的位置  -->
    <!--如需文字提示，可在外部添加element的<el-tooltip></el-tooltip>元素  -->
    <el-tooltip placement="top" content="回到顶部">
      <back-to-top transitionName="fade" :customStyle="myBackToTopStyle" :visibilityHeight="300" :backPosition="50"></back-to-top>
    </el-tooltip>
  </div>
</template>

<script>

import withrawPay from '../outlets/withdrawPay'
import lookDrawLog from '../outlets/outletWithdrawLog'
import BackToTop from '@/components/BackToTop' // 回到顶部
import * as api from '@/api/main-api' // API
import waves from '@/directive/waves' // 水波纹指令
import { mapGetters } from 'vuex'

export default {
  name: 'withrawCheck',

  directives: {
    waves
  },

  components: { BackToTop, withrawPay, lookDrawLog },
  data() {
    return {
      // 回到顶部样式
      myBackToTopStyle: {
        right: '50px',
        bottom: '50px',
        width: '40px',
        height: '40px',
        'z-index': '9999',
        'border-radius': '4px',
        'line-height': '45px', // 请保持与高度一致以垂直居中 Please keep consistent with height to center vertically
        background: '#e7eaf1'// 按钮的背景颜色 The background color of the button
      },
      // 长带参数
      listQuery: {
        page: 1,
        pagesize: 10
      },

      // 搜索字段
      search: {
        outlet: '',
        status: ''
      },
      total: 0,
      listLoading: false,
      listData: [],
      totalTop: [],
      // 状态
      stateOptions: [
        { id: '0', name: '待审核' },
        { id: '1', name: '已审核' },
        { id: '2', name: '拒绝' }
      ],
      outletOptions: [],
      // 编辑传值
      editVisible: false,
      // 查看详情
      lookVisible: false,
      propsData: {}
    }
  },

  computed: {
    ...mapGetters([
      'outlet_id'
    ])
  },
  // 初始化数据
  created() {
    this.selectOutlet()
    // 数据列
    setTimeout(() => {
      this.fetchData()
    }, 100)
  },

  // 触动方法
  methods: {
    // 控制每页调数
    handleSizeChange(val) {
      this.listQuery.pagesize = val
      this.fetchData()
    },

    // 跳页
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.fetchData()
    },

    // 搜搜
    handleFilter() {
      this.listQuery.page = 1
      this.fetchData()
    },

    // 子窗口关闭,刷新数据
    isrefresh(data) {
      this.fetchData()
    },

    // 去结算
    handlEdit(row) {
      // 需要请求锁定行
      this.propsData = row
      this.propsData.unit_id = this.outlet_id
      if (row.action_user === '0') {
        var postData = {
          account_id: row.id,
          admin_id: row.admin_id,
          iscancel: 1
        }
        this.lockAccount(postData)
      }
    },

    // 订单提现详情
    handlLook(row) {
      this.lookVisible = !this.lookVisible
      this.$refs.lookLog.setFetchData(row)
    },

    // 获取营业点的提现审核列表数据
    fetchData() {
      this.listLoading = true
      this.listQuery = Object.assign(this.listQuery, this.search)
      return new Promise((resolve, reject) => {
        api.outletWithdrawApi(this.listQuery).then(response => {
          if (response.data.code === 0) {
            this.listData = response.data.data
            this.total = parseInt(response.data.total)
          }
          this.listLoading = false
        })
      })
    },

    // 选择加盟店列
    selectOutlet() {
      this.listLoading = true
      var postData = {
        islocal: 2
      }
      return new Promise((resolve, reject) => {
        api.selectOutleApi(postData).then(response => {
          if (response.data.code === 0) {
            this.outletOptions = response.data.data
          }
          this.listLoading = false
        })
      })
    },

    // 锁行操作
    lockAccount(datas) {
      api.lockAccountApi(datas).then(response => {
        if (response.data.data === true) {
          this.editVisible = true
        } else {
          this.editVisible = false
        }
        this.$root.message('该条提现已被锁定', 'success')
      })
    }
  }

}
</script>

<style>
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
</style>
